<template>
  <div class="container-fluid" id="course">
    <div class="row ">
      <Breadcrumb1 v-bind:Breadcrumbs="Breadcrumbs"></Breadcrumb1>
    </div>
    <div class="row mga">
      <el-steps class="col" :active="1" finish-status="success" simple>
        <el-step title="基础信息添加"></el-step>
        <el-step title="步骤 2"></el-step>
        <el-step title="步骤 2"></el-step>
        <el-step title="步骤 2"></el-step>
        <el-step title="步骤 3"></el-step>
      </el-steps>
    </div>
    <div class="row ">
      <div class="col">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="课程名称" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>
                    <el-form-item label="课程价格" prop="coursePrize">
                      <el-input-number v-model="ruleForm.coursePrize" :min="0" :max="1000" label="填写价格"></el-input-number>
          </el-form-item>
                    <el-form-item label="课程简介" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>

          <el-form-item label="课程难度" prop="difficulty">
            <el-select v-model="ruleForm.difficulty" placeholder="请选择课程难度">
              <el-option label="初级" value="初级"></el-option>
              <el-option label="中级" value="中级"></el-option>
              <el-option label="高级" value="高级"></el-option>
              <el-option label="顶级" value="顶级"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开发环境，需要的结构" >
            <el-checkbox-group 
            v-model="ruleForm.environments">
            <el-checkbox v-for="city in material" name="environment" :label="city" :key="city">{{city}}</el-checkbox>
          </el-checkbox-group>
          </el-form-item>
          <el-form-item label="课程logo 图片16:9" prop="resource">
            <el-upload
              action="https://jsonplaceholder.typicode.com/posts/"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove">
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="dialogVisible">
              <img width="100%" :src="dialogImageUrl" alt="">
            </el-dialog>
          </el-form-item>
          <el-form-item label="活动形式" prop="desc">
            <el-input type="textarea" id="editor" ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import Breadcrumb1 from "@/components/Breadcrumb.vue";
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
export default {
  name: "addCourse",
  data() {
    return {
      material: [
        "LED灯",
        "蜂鸣器",
        "IMU(加速度计)",
        "触碰开关",
        "拾音传感器",
        "灰度传感器",
        "光敏传感器",
        "人体红外传感器",
        "光电开关",
        "温度传感器",
        "火焰传感器",
        "震动传感器",
        "磁力传感器",
        "舵机",
        "电机",
        "螺旋桨",
        "多空板",
        "电源",
        "起件器",
        "铰链",
        "联轴器",
        "齿轮",
        "浆叶",
        "Mirco USB",
        "3芯数据线",
        "4芯数据线",
        "万向轮",
        "轮子",
        "控制器(Duino)"
      ],
      editor: null,
      active: 0,
      dialogImageUrl: "",
      dialogVisible: false,
      Breadcrumbs: [
        {
          name: "home",
          title: "首页",
          params: null
        },
        {
          name: "addCourse",
          title: "添加课程",
          params: null
        }
      ],
      ruleForm: {
        difficulty: "初级",
        coursePrize: 0,
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
        environments: []
      },
      rules: {
        difficulty: [
          { required: true, message: "请输入课程难度", trigger: "blur" }
        ],
        coursePrize: [
          { required: true, message: "请输入课程价格", trigger: "blur" }
        ],
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" }
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change"
          }
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ],
        type: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个活动性质",
            trigger: "change"
          }
        ],
        resource: [
          { required: true, message: "请选择活动资源", trigger: "change" }
        ],
        desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }]
      }
    };
  },
  mounted() {
    ClassicEditor.create(document.querySelector("#editor")).catch(error => {
      console.error(error);
    });
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    }
  },
  components: {
    Breadcrumb1
  }
};
</script>

<style scoped>
</style>